package com.yitiao.data_algorithms.leetcode.editor.cn;

import com.yitiao.data_algorithms.leetcode.editor.cn.base.ListNode;
import com.yitiao.data_algorithms.leetcode.editor.cn.base.TreeNode;

class HeBingLiangGePaiXuDeLianBiaoLcof {
    //leetcode submit region begin(Prohibit modification and deletion)

    /**
     * Definition for singly-linked list.
     * public class ListNode {
     * int val;
     * ListNode next;
     * ListNode(int x) { val = x; }
     * }
     */
    class Solution {
        public ListNode mergeTwoLists(ListNode l1, ListNode l2) {
            ListNode ans = new ListNode(0);
            ListNode dummy = ans;
            while (l1 != null && l2 != null) {
                if (l1.val < l2.val) {
                    ans.next = l1;
                    l1 = l1.next;
                } else {
                    ans.next = l2;
                    l2 = l2.next;
                }
                ans = ans.next;
            }
            ans.next = l1 == null ? l2 : l1;
            return dummy.next;
        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}